﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Orgs;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.Orgs.Pages
{
    public partial class NodeType_Edit : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindNodeType();
            }
        }

        public void BindNodeType()
        {
            String nodeTypeCode = Request.QueryString["NodeTypeCode"] ?? String.Empty;
            OrgsService services = new OrgsService();
            NodeType node = services.GetType(nodeTypeCode);
            this.txt_code.Text = node.Code;
            this.txt_caption.Text = node.Caption;
            this._ctlCheckPost.Checked = node.IsPost;
        }

        public void Save_NodeType(object sender, EventArgs e)
        {
            OrgsService services = new OrgsService();
            NodeType node = new NodeType();
            node.Id = new Guid(Request.QueryString["NodeTypeId"] ?? String.Empty);
            node.Code = this.txt_code.Text;
            node.Caption = this.txt_caption.Text;
            node.IsPost = this._ctlCheckPost.Checked;
            ServiceResult result = services.SaveType(node);

            if (result.IsSuccess)
            {
                Response.Redirect("NodeType-List.aspx");
            }
        }
    }
}